/*
 * JaCoLiB
 * Copyright (C) 2008 Alessandro Serra
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package it.gashale.jacolib.console;


import it.gashale.jacolib.core.JacolibError;

import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;

public class TmpFileConsole extends FileConsole {
	private final static String default_out_file_name="console_out.txt";
	private final static String default_err_file_name="console_err.txt";
	
	public TmpFileConsole(File tmpdir, String out, String err) 
				throws FileNotFoundException {
		super(tmpdir,out,err);
	}
	public TmpFileConsole(File tmpdir) 
				throws FileNotFoundException {
		super(tmpdir,default_out_file_name,default_err_file_name);
	}
	public TmpFileConsole() throws JacolibError, IOException {
		super(makeTempDirectory(),default_out_file_name,default_err_file_name);
	}
	
	static private File makeTempDirectory() throws JacolibError, IOException {
		File dummyFile = File.createTempFile("Jacolib_","");
		dummyFile.delete();
		File temp_dir = new File(dummyFile.getAbsolutePath());
		temp_dir.mkdir();
		temp_dir.deleteOnExit();
		return temp_dir;
	}
}
